package com.bms.actions;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.bms.utils.DB;
import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport{
	
	public String emailId;
	public String password;

	
	
	public String getEmailId() {
		return emailId;
	}
	public void setEmailId(String emailId) {
		this.emailId = emailId;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public  String execute(){
		Connection con;
		try{
			con =  DB.getConnection();
			ResultSet result;
			String query = "select emailid,pwd from user";
			result = DB.readFromDB(query,con);
			System.out.println("users: " + emailId + password);
			while(result.next()){
				String email = result.getString("emailid");
				String pwd = result.getString("pwd");
				System.out.println("uanme:" + email +"pwd" + pwd);
				if(email.equals(emailId) && pwd.equals(password)){
					System.out.println("success");
					return SUCCESS;
				}
			}
		}
		catch(Exception e){
			System.out.println("Exception :" +e);
		}
		System.out.println("faiuleur");
		emailId = "";
		password="";
		addActionError(getText("Incorrect Username/Password "));
		return "failure";
	}
}
